<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * PISOneAM
 *
 * 专业IT监控系统
 *
 * @package		PISOneAM
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008 - 2011, EllisLab, Inc.
 * @license		http://www.m135.com/license.html
 * @link		http://www.m135.com
 * @since		Version 1.0
 * @filesource
 */
class Login extends CI_Controller
{
	
	function index()
	{
		$this->load->helper(array('form', 'url'));
		$this->load->view('login');
	}
	/**
	* 检测用户是否登录，成功跳转到主页，失败返回登录页
	* @author PISOne项目开发团队  
	* @param 
	* @return int/bool/object/array
	*/
	function check_login()
	{
		$this->load->library('form_validation');
		$this->form_validation->set_rules('UserAccount', '用户账户', 'required');
		$this->form_validation->set_rules('PassWord', '密码', 'required');
		$this->form_validation->set_rules('PassWorddb', '校验密码', 'callback_password_check');
		if ($this->form_validation->run() == FALSE)//验证不成功
		{
			$this->load->view('login');
		}
		else 
		{
				redirect(base_url()."index.php");
		}
	}
	/**
	* 校验密码并设置返回值 属于check_login 的返回值
	* @author PISOne项目开发团队  
	* @param 
	* @return int/bool/object/array
	*/
	function password_check()
	{
		$this->load->model('musers');
		$data =$this->musers->validate_user($_POST['UserAccount'],$_POST['PassWord']);
		if($data)
		{
			$data['UserAcconut']=$_POST['UserAccount'];
			$data['UserIP']=$_SERVER['HTTP_HOST'];
			$data['UserName']=$this->musers->_UserName;
			$this->session->set_userdata($data);
			return TRUE;
		}
		else
		{
			//redirect(base_url()."index.php/login");
			$this->form_validation->set_message('password_check','用户名或密码无效');
			//$this->load->view('login');
			return FALSE;
		}
	}
	
	/**
	* 用户退出
	* @author PISOne项目开发团队  
	* @param 
	* @return int/bool/object/array
	*/
	function user_exit()
	{
		$this->session->sess_destroy();
		redirect(base_url()."index.php");
	}
}
